﻿@{
    ViewBag.Title = "upload";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section style {
    <style type="text/css">
        .uploadDiv {

            width:300px;
            height:200px;
            background-color : orangered;
            margin : 50px auto;
        }
    </style>
    }

<div class="uploadDiv">

    <input type="file" id="fileUpload" name="fileUpload" /> <br />
    <input type="button" id="fileUploadBtn" value="文件上传" />
</div>


@section script {
    <script type="text/javascript" src="/Static/Template/js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#fileUploadBtn").on("click", function () {
                $.ajaxFileUpload({
                    url: '/Test/upload',             //用于文件上传的服务器端请求地址
                    type: 'post',
                    data: { ProdcutID: 1 },
                    secureuri: false,                   //是否需要安全协议，一般设置为false
                    fileElementId: 'fileUpload',        //文件上传域的ID 在这里设置要上传的多个input的ID
                    dataType: 'json',                   //返回值类型 一般设置为json
                    success: function (data, status)    //服务器成功响应处理函数
                    {
                        console.log(data);
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
                });
            });
        });
    </script>
}

